package com.newtouch.fileupload.controller;

import com.newtouch.fileupload.entity.Chunk;
import com.newtouch.fileupload.service.BigFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 李建 2020年5月19日17:05:57
 * 文件Controller
 * 处理文件的上传与下载
 */
@RestController
@RequestMapping("/bigFile")
public class BigFileController {
    @Autowired
    BigFileService bigFileService;

    /**
     * 处理文件上传POST请求
     * 将上传的文件存放到服务器内
     * @param chunk 文件块
     * @param response 响应
     * @return 上传响应状态
     */
    @PostMapping("/fileUpload")
    public String uploadPost(@Validated Chunk chunk, HttpServletResponse response){
        return bigFileService.fileUploadPost(chunk,response);
    }
}
